I wanted to take a closer look at my personal spotify library and try to find any interesting groupings or clusters that would be usefull when creating playlist.
This analysis is focused on clustering and exploring the attributes behind the music I listen to. With these models, I hope to strategically and quickly create playlists with songs more similar to eachother based off songs in my current library.
The data is collected using a spotify API connection library in python. I saved the data into a .csv file and use pandas for handling.
Most of the features are numeric values that rate and measure certain attributes of each track. For example: 'Danceability (float) describes how suitable a track is for dancing based on a combination of musical elements including tempo, rhythm stability, beat strength, and overall regularity. A value of 0.0 is least danceable and 1.0 is most danceable. The distribution of values for this feature look like this:Danceability distribution'.
import pandas as pd
df = pd.read_csv("C:\\Users\\jbaskerville\\Desktop\\JohnBaskervilleGitRepos\\SpotifyClustering\\Juypter Notebooks\\spotifyLibrary.csv", encoding='utf-8')
df.head()
| Unnamed: 0 | danceability | energy | key | loudness | mode | speechiness | acousticness | instrumentalness | liveness | valence | tempo | type | id | uri | track_href | analysis_url | duration_ms | time_signature | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0.730 | 0.677 | 4 | -7.599 | 0 | 0.3220 | 0.05110 | 0.0 | 0.0623 | 0.586 | 108.695 | audio_features | 21AJQhGZpujjZQXByZAXpr | spotify:track:21AJQhGZpujjZQXByZAXpr | https://api.spotify.com/v1/tracks/21AJQhGZpujj... | https://api.spotify.com/v1/audio-analysis/21AJ... | 190345 | 3 |
| 1 | 0 | 0.801 | 0.688 | 1 | -4.594 | 1 | 0.3960 | 0.14400 | 0.0 | 0.1070 | 0.500 | 162.928 | audio_features | 1MIGkQxcdAt2lDx6ySpsc5 | spotify:track:1MIGkQxcdAt2lDx6ySpsc5 | https://api.spotify.com/v1/tracks/1MIGkQxcdAt2... | https://api.spotify.com/v1/audio-analysis/1MIG... | 157675 | 4 |
| 2 | 0 | 0.597 | 0.433 | 10 | -10.280 | 0 | 0.0444 | 0.07620 | 0.0 | 0.1170 | 0.159 | 114.915 | audio_features | 0xgMhStlvnlNzwewETY4L6 | spotify:track:0xgMhStlvnlNzwewETY4L6 | https://api.spotify.com/v1/tracks/0xgMhStlvnlN... | https://api.spotify.com/v1/audio-analysis/0xgM... | 144000 | 4 |
| 3 | 0 | 0.914 | 0.655 | 6 | -5.333 | 0 | 0.2940 | 0.00245 | 0.0 | 0.0817 | 0.705 | 143.975 | audio_features | 4LH1gsNA3wUS6QKkGZoJN8 | spotify:track:4LH1gsNA3wUS6QKkGZoJN8 | https://api.spotify.com/v1/tracks/4LH1gsNA3wUS... | https://api.spotify.com/v1/audio-analysis/4LH1... | 153863 | 4 |
| 4 | 0 | 0.733 | 0.820 | 1 | -7.288 | 1 | 0.2400 | 0.23900 | 0.0 | 0.3350 | 0.625 | 97.732 | audio_features | 3f4NZkjWlw6jsS8B7I49hE | spotify:track:3f4NZkjWlw6jsS8B7I49hE | https://api.spotify.com/v1/tracks/3f4NZkjWlw6j... | https://api.spotify.com/v1/audio-analysis/3f4N... | 209480 | 4 |
len(df)
1573
df.describe()
| Unnamed: 0 | danceability | energy | key | loudness | mode | speechiness | acousticness | instrumentalness | liveness | valence | tempo | duration_ms | time_signature | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| count | 1546.0 | 1546.000000 | 1546.000000 | 1546.000000 | 1546.000000 | 1546.000000 | 1546.000000 | 1546.000000 | 1546.000000 | 1546.000000 | 1546.000000 | 1546.000000 | 1.546000e+03 | 1546.000000 |
| mean | 0.0 | 0.694001 | 0.635506 | 5.154592 | -6.842761 | 0.550453 | 0.159082 | 0.172590 | 0.046865 | 0.190313 | 0.440288 | 124.822257 | 2.196170e+05 | 3.974774 |
| std | 0.0 | 0.146338 | 0.159924 | 3.638170 | 2.444221 | 0.497609 | 0.131273 | 0.197361 | 0.159087 | 0.140855 | 0.223067 | 27.460047 | 5.721245e+04 | 0.261952 |
| min | 0.0 | 0.157000 | 0.109000 | 0.000000 | -21.447000 | 0.000000 | 0.024400 | 0.000025 | 0.000000 | 0.016000 | 0.026600 | 55.679000 | 5.564000e+04 | 1.000000 |
| 25% | 0.0 | 0.598000 | 0.529000 | 1.000000 | -8.163750 | 0.000000 | 0.051500 | 0.024400 | 0.000000 | 0.101000 | 0.265000 | 103.955000 | 1.865490e+05 | 4.000000 |
| 50% | 0.0 | 0.708000 | 0.636000 | 5.000000 | -6.567000 | 1.000000 | 0.107000 | 0.092100 | 0.000004 | 0.134000 | 0.417500 | 125.990000 | 2.138250e+05 | 4.000000 |
| 75% | 0.0 | 0.805750 | 0.750000 | 8.000000 | -5.188750 | 1.000000 | 0.247000 | 0.258000 | 0.001450 | 0.237750 | 0.599000 | 142.977250 | 2.467598e+05 | 4.000000 |
| max | 0.0 | 0.980000 | 0.994000 | 11.000000 | -0.283000 | 1.000000 | 0.855000 | 0.944000 | 0.973000 | 0.966000 | 0.980000 | 215.593000 | 1.146163e+06 | 5.000000 |
For data cleaning, I elimintated a few non-float varibles like 'href' and 'id' which wouldnt help the clustering algorithm. After all the numeric data were identified, one of the first exploration techniques I use to understand the data involves looking at the feature correlations. If I wasnt using PCA later on, I would consider the correlation between loudness and energy as 'high' and look at alternative feature engineering techniques.Next, I fed the data through a pipeline that systematically log transformed and scaled the data using MinMaxScaler and numpy.log1p().
import seaborn as sns
numeric_data = [x for x in df.columns if x not in ["key","mode","time_signature",
"type","uri","id","track_href","Unnamed: 0",
"analysis_url"]]
numeric_data_df = df[numeric_data].set_index(df['id'])
numeric_data_df.columns
Index(['danceability', 'energy', 'loudness', 'speechiness', 'acousticness',
'instrumentalness', 'liveness', 'valence', 'tempo', 'duration_ms'],
dtype='object')
sns.pairplot(numeric_data_df);
Next I wanted to look at inertia (tightness of clusters) and try to create playlists with clusters of smaller inertia keeping in mind there are over 1,500 records. I found the inertia for 1 cluster all the way through 50 clusters. and plotted on a graph.
The inertia is lowest with the model that finds 50 clusters and the range of songs in the created playlist was 11-56. When I look at the playlists created I found similarities in the songs that were grouped together. I also found duplicates in a few of the playlists which gave me confidence in the clustering algorithm.
The second model implemented was a mean-shift algorithm where the number of clusters was decided by the model and the parameter 'quantile' (0-1) was tuned to 0.1. The 10 playlists created were a little similar in size ranging from 82-247.
The last models I trained used data with fewer features and experimented with deminsionality reduction using Kernel PCA. I experimented with data that ranged from 1-10 features and viewed the outputed playlists to try and find any interesting playlist combinations. I was able to find a a lot of uniqe playlist that grouped songs with similar sounds together. My library is mostly hip hop and rap but the latest models were able to put groups of songs together that were not typical sound of the overall library.
The best model is K-Means for this application because the user will have the biggest control over playlist size and k-means gernerally groups songs in similar cluster sizes. After investigating the playlists, the k-means model was able to create reliable groups of songs that I would consider putting into my library for personal use.
I found skipping the log tranformation step made the k-means model more likely to pick out and place 'the beep test'(a unique running exercise saved as a song) into its own cluster of 1 song. Implementing the log transformation to the data caused a more smooth and rounded set of playlist but track was incorrectly grouped together with other songs while it felt more like an outlier.
I found it incouraging that multiple songs made by the same artists made it into the same playlist and outlier songs were picked out.
import pandas as pd
df = pd.read_csv("spotifyLibrary.csv", encoding='utf-8')
numeric_data = [x for x in df.columns if x not in ["key","mode","time_signature",
"type","uri","id","track_href","Unnamed: 0",
"analysis_url"]]
numeric_data_df = df[numeric_data].set_index(df['id'])
numeric_data_df
from matplotlib import pyplot as plt
import seaborn as sns
import numpy as np
#create figure for heatmap plot
plt.figure(figsize = (15,10)) # width x height
corr = numeric_data_df.corr()
cmap = sns.diverging_palette(220, 10, as_cmap=True)
mask = np.triu(np.ones_like(corr, dtype=bool))
#use heatmatp function to visualize correlations
corrHeatmap = sns.heatmap(corr, mask= mask, cmap=cmap,annot=True)
# numeric_data_df.describe()
#rank correlated values in descending order
for x in range(len(corr)):
corr.iloc[x,x] = 0.0
corr.abs().max().sort_values(ascending=False)
loudness 0.689309 energy 0.689309 acousticness 0.348617 valence 0.343929 danceability 0.244221 duration_ms 0.195918 instrumentalness 0.193735 speechiness 0.193735 liveness 0.142388 tempo 0.085164 dtype: float64
# #Create a pairplot of the original data to get an idea of shape and distribution of features
# sns.set_context('notebook')
# sns.set_style('white')
# sns.pairplot(numeric_data_df);
# print out features with skew greater than 0.75.
skew_columns = numeric_data_df.skew().sort_values(ascending=False)
skew_columns = skew_columns.loc[skew_columns > 0.75]
skew_columns
instrumentalness 3.974277 duration_ms 3.532412 liveness 1.993550 acousticness 1.466420 speechiness 1.149868 dtype: float64
import numpy as np
from scipy import stats
#t_data_df will be the transformed data for addressing skewness
t_data_df = numeric_data_df.copy()
#(numeric_data_df.instrumentalness).unique().size
#np.sqrt(numeric_data_df.instrumentalness).hist()
t_data_df['instrumentalness'] = t_data_df['instrumentalness'].replace(0,0.0000001)
t_data_df['instrumentalness'] = stats.boxcox(t_data_df['instrumentalness'])[0]
t_data_df['duration_ms'] = np.log(t_data_df['duration_ms'])
t_data_df['liveness'] = np.log(t_data_df['liveness'])
t_data_df['acousticness'] = stats.boxcox(t_data_df['acousticness'])[0]
t_data_df['speechiness'] = np.log(t_data_df['speechiness'])
skew_columns = t_data_df.skew().sort_values(ascending=False)
skew_columns = skew_columns.loc[skew_columns > 0.75]
skew_columns
Series([], dtype: float64)
# t_data_df['instrumentalness'].skew()
# (t_data_df['duration_ms']).skew()
# (t_data_df['liveness']).skew()
# (t_data_df['acousticness']).skew()
skew_data = ['instrumentalness','duration_ms','liveness','acousticness','speechiness']
sns.pairplot(t_data_df[skew_data])
<seaborn.axisgrid.PairGrid at 0x1efffa30ca0>
from sklearn.preprocessing import MinMaxScaler
sc = MinMaxScaler()
scaledFeatures = sc.fit_transform(t_data_df)
scaledFeatures_df = pd.DataFrame(scaledFeatures, index=t_data_df.index, columns=t_data_df.columns)
scaledFeatures_df
| danceability | energy | loudness | speechiness | acousticness | instrumentalness | liveness | valence | tempo | duration_ms | |
|---|---|---|---|---|---|---|---|---|---|---|
| id | ||||||||||
| 21AJQhGZpujjZQXByZAXpr | 0.696233 | 0.641808 | 0.654319 | 0.725420 | 0.463214 | 0.000000 | 0.331508 | 0.586742 | 0.331528 | 0.406554 |
| 1MIGkQxcdAt2lDx6ySpsc5 | 0.782503 | 0.654237 | 0.796305 | 0.783584 | 0.614283 | 0.000000 | 0.463408 | 0.496539 | 0.670667 | 0.344311 |
| 0xgMhStlvnlNzwewETY4L6 | 0.534629 | 0.366102 | 0.527641 | 0.168327 | 0.517251 | 0.000000 | 0.485197 | 0.138871 | 0.370424 | 0.314322 |
| 4LH1gsNA3wUS6QKkGZoJN8 | 0.919806 | 0.616949 | 0.761387 | 0.699841 | 0.181133 | 0.000000 | 0.397619 | 0.711559 | 0.552147 | 0.336221 |
| 3f4NZkjWlw6jsS8B7I49hE | 0.699878 | 0.803390 | 0.669013 | 0.642779 | 0.702366 | 0.000000 | 0.741735 | 0.627648 | 0.262973 | 0.438217 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 2rmq49FcJ4U3wh1Z7C9UxE | 0.591738 | 0.418079 | 0.618739 | 0.557165 | 0.641012 | 0.000000 | 0.899219 | 0.614013 | 0.151644 | 0.389329 |
| 3Z2sglqDj1rDRMF5x0Sz2R | 0.383961 | 0.397740 | 0.707475 | 0.734865 | 0.619900 | 0.000000 | 0.440233 | 0.617160 | 0.689783 | 0.475107 |
| 14Rcq31SafFBHNEwXrtR2B | 0.752126 | 0.343503 | 0.661926 | 0.382789 | 0.217068 | 0.506702 | 0.368148 | 0.273128 | 0.277174 | 0.466046 |
| 439TlnnznSiBbQbgXiBqAd | 0.400972 | 0.700565 | 0.691363 | 0.676936 | 0.469901 | 0.361863 | 0.808225 | 0.199706 | 0.221175 | 0.608003 |
| 29gsi1zZrZxdStACmTQB0Z | 0.670717 | 0.542373 | 0.645955 | 0.161273 | 0.462201 | 0.000000 | 0.316160 | 0.580449 | 0.489282 | 0.531840 |
1573 rows × 10 columns
from sklearn.cluster import KMeans
from sklearn.metrics import pairwise_distances_argmin_min
km = KMeans(n_clusters=3,random_state=42)
km = km.fit(scaledFeatures_df)
df['kmeans'] = km.predict(scaledFeatures_df)
df.groupby(['kmeans']).size()
kmeans 0 421 1 801 2 351 dtype: int64
closest, _ = pairwise_distances_argmin_min(km.cluster_centers_, scaledFeatures_df)
scaledFeatures_df.iloc[closest]
| danceability | energy | loudness | speechiness | acousticness | instrumentalness | liveness | valence | tempo | duration_ms | |
|---|---|---|---|---|---|---|---|---|---|---|
| id | ||||||||||
| 43nBJsVLjMDqL266IlPKif | 0.585662 | 0.749153 | 0.731998 | 0.310815 | 0.383697 | 0.839019 | 0.532422 | 0.508076 | 0.627887 | 0.430740 |
| 6Yrq88ZgV8XGdFDJ0RVoMM | 0.815310 | 0.674576 | 0.652287 | 0.584396 | 0.532405 | 0.000000 | 0.532422 | 0.348647 | 0.452206 | 0.360894 |
| 4bOr88BuLILM22g8FKQWrG | 0.642770 | 0.485876 | 0.568843 | 0.373175 | 0.869577 | 0.697090 | 0.528963 | 0.349696 | 0.426792 | 0.457624 |
df.loc[closest,'kmeans'] = 3
df['size'] = 10
df.loc[closest,'size'] = 30
!pip install plotly
Collecting plotly Downloading plotly-5.1.0-py2.py3-none-any.whl (20.6 MB) Requirement already satisfied: six in c:\users\jbaskerville\anaconda3\lib\site-packages (from plotly) (1.15.0) Collecting tenacity>=6.2.0 Downloading tenacity-8.0.1-py3-none-any.whl (24 kB) Installing collected packages: tenacity, plotly Successfully installed plotly-5.1.0 tenacity-8.0.1
import plotly.express as px
from sklearn.decomposition import PCA
pca = PCA(n_components=2)
components = pca.fit_transform(scaledFeatures_df)
fig = px.scatter(components, x=0, y=1, color= df['kmeans'])
fig.update_traces(marker=dict(size=df['size']),
selector=dict(mode='markers'))
fig.show()
pca = PCA(n_components=3)
components = pca.fit_transform(scaledFeatures_df)
fig = px.scatter_3d(components, x=0, y=1,z=2, color= df['kmeans'])
fig.update_traces(marker=dict(size=df['size']),
selector=dict(mode='markers'))
fig.show()
# # #create and fit a range of models
# km_list = list()
# for clust in range(1,50):
# km = KMeans(n_clusters = clust, random_state=42)
# km = km.fit(scaledFeatures_df)
# km_list.append(pd.Series({
# 'clusters':clust,
# 'inertia':km.inertia_,
# 'model':km
# }))
# plot_data = (pd.concat(km_list,axis=1)
# .T[['clusters','inertia']]
# .set_index('clusters'))
# ax = plot_data.plot(marker='o',ls='-')
# ax.set_xticks(range(0,51,2))
# ax.set_xlim(0,51)
# ax.set(xlabel='Cluster',ylabel='Inertia')
scaledFeatures_df.iloc[closest]
| danceability | energy | loudness | speechiness | acousticness | instrumentalness | liveness | valence | tempo | duration_ms | |
|---|---|---|---|---|---|---|---|---|---|---|
| id | ||||||||||
| 43nBJsVLjMDqL266IlPKif | 0.585662 | 0.749153 | 0.731998 | 0.310815 | 0.383697 | 0.839019 | 0.532422 | 0.508076 | 0.627887 | 0.430740 |
| 6Yrq88ZgV8XGdFDJ0RVoMM | 0.815310 | 0.674576 | 0.652287 | 0.584396 | 0.532405 | 0.000000 | 0.532422 | 0.348647 | 0.452206 | 0.360894 |
| 4bOr88BuLILM22g8FKQWrG | 0.642770 | 0.485876 | 0.568843 | 0.373175 | 0.869577 | 0.697090 | 0.528963 | 0.349696 | 0.426792 | 0.457624 |
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import spotipy.util as util
username= 'john3baskerville'
token = util.prompt_for_user_token(username,
'user-library-read',
client_id='97537d196d1345ecb17c19537d54174a',
client_secret='003cf70c6be14a9e991e75f52930c5e3',
redirect_uri='http://localhost:8080')
sp = spotipy.Spotify(auth=token)
# tracks = sp.tracks(minPlaylist[:50])
# for value in tracks['tracks']:
# print(value['name'],"-", value['artists'][0]['name'])
songIds = df['id'][df['kmeans'] == 3]
tracks = sp.tracks(songIds)
for value in tracks['tracks']:
print(value['name'])
for artist in value['artists']:
print(" " + artist['name'])
Stand Off MEMBA Ehiorobo FALL BACK Duckwrth Will He (Medasin Remix) Joji Medasin
df.columns
Index(['Unnamed: 0', 'danceability', 'energy', 'key', 'loudness', 'mode',
'speechiness', 'acousticness', 'instrumentalness', 'liveness',
'valence', 'tempo', 'type', 'id', 'uri', 'track_href', 'analysis_url',
'duration_ms', 'time_signature', 'kmeans', 'size'],
dtype='object')
sns.histplot(x='valence',data = df, hue="kmeans")
<AxesSubplot:xlabel='valence', ylabel='Count'>
from sklearn.cluster import MeanShift, estimate_bandwidth
bandwidth = estimate_bandwidth(scaledFeatures_df, quantile=.03, n_samples=1500)
ms = MeanShift(bandwidth=bandwidth, bin_seeding=True)
msFit = ms.fit(scaledFeatures_df)
df['meanshift'] = msFit.predict(scaledFeatures_df)
df.groupby(['meanshift']).size().to_frame
<bound method Series.to_frame of meanshift 0 773 1 636 2 22 3 40 4 44 5 2 6 12 7 38 8 6 dtype: int64>
pca = PCA(n_components=3)
components = pca.fit_transform(scaledFeatures_df)
fig = px.scatter_3d(components, x=0, y=1,z=2, color = df['meanshift'])
fig.show()
# from sklearn.preprocessing import FunctionTransformer
# from sklearn.pipeline import Pipeline
# #custom log transformer
# log_transformer = FunctionTransformer(np.log1p)
# #Pipeline
# estimators = [('minmaxscale', MinMaxScaler())]
# pipeline = Pipeline(estimators)
# #convert Original data using the newly created pipeline from above
# pipe_data = pipeline.fit_transform(numeric_data_df)
# data_pipe_df = pd.DataFrame(data_pipe, index=numeric_data_df.index, columns=PipeData.columns)
from sklearn.decomposition import KernelPCA
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import mean_squared_error
# Custom scorer--use negative rmse of inverse transform
def scorer(pcamodel, X, y=None):
try:
X_val = X.values
except:
X_val = X
# Calculate and inverse transform the data
data_inv = pcamodel.fit(X_val).transform(X_val)
data_inv = pcamodel.inverse_transform(data_inv)
# The error calculation
mse = mean_squared_error(data_inv.ravel(), X_val.ravel())
# Larger values are better for scorers, so take negative value
return -1.0 * mse
# The grid search parameters
param_grid = {'gamma':[0.001, 0.01, 0.05, 0.1, 0.5, 1.0],
'n_components': [2, 3, 4,5,6,7,8,9,10]}
# The grid search
kernelPCA = GridSearchCV(KernelPCA(kernel='rbf', fit_inverse_transform=True),
param_grid=param_grid,
scoring=scorer,
n_jobs=-1)
kpca_list = list()
kpcafeature_weight_list = list()
for n in range(1,11):
kPCAmod = KernelPCA(kernel='linear',n_components=n, fit_inverse_transform=True)
# Calculate and inverse transform the data
data_inv = kPCAmod.fit(scaledFeatures_df).transform(scaledFeatures_df)
data_inv = kPCAmod.inverse_transform(data_inv)
# The error calculation
mse = mean_squared_error(data_inv.ravel(), scaledFeatures_df.values.ravel())
kpca_list.append(pd.Series({'n':n,'model':kPCAmod,'mse':mse}))
kpca_df = pd.concat(kpca_list,axis=1).T.set_index('n')
kpca_df
kpca_data = kpca_list[0].model.fit(scaledFeatures).transform(scaledFeatures_df)
kpca_data.shape
kpca = KernelPCA(n_components=3)
kpcacomponents = kpca.fit_transform(scaledFeatures_df)
fig = px.scatter_3d(kpcacomponents, x=0, y=1,z=2, color = df['kmeans'])
fig.show()
from sklearn.decomposition import PCA
pca_list = list()
feature_weight_list = list()
for n in range(1,11):
PCAmod = PCA(n_components=n)
PCAmod.fit(scaledFeatures_df)
pca_list.append(pd.Series({'values':PCAmod.singular_values_,'n':n,'model':PCAmod,'var':PCAmod.explained_variance_ratio_.sum()}))
weights = PCAmod.explained_variance_ratio_.reshape(-1,1)/PCAmod.explained_variance_ratio_.sum()
overall_contribution = np.abs(PCAmod.components_)*weights
abs_feature_values = overall_contribution.sum(axis=0)
feature_weight_list.append(pd.DataFrame({'n':n,'features':scaledFeatures_df.columns,'values':abs_feature_values/abs_feature_values.sum()}))
pca_df = pd.concat(pca_list,axis=1).T.set_index('n')
pca_df
#import spotipy
# from spotipy.oauth2 import SpotifyClientCredentials
# import spotipy.util as util
# username= 'john3baskerville'
# token = util.prompt_for_user_token(username,
# 'user-library-read',
# client_id='97537d196d1345ecb17c19537d54174a',
# client_secret='003cf70c6be14a9e991e75f52930c5e3',
# redirect_uri='http://localhost:8080')
# sp = spotipy.Spotify(auth=token)
# tracks = sp.tracks(minPlaylist[:50])
# for value in tracks['tracks']:
# print(value['name'],"-", value['artists'][0]['name'])
#minPlaylist = scaledFeatures_df[scaledFeatures_df['KPCAMeanShift'] == 1].index
# username= 'john3baskerville'
# token = util.prompt_for_user_token(username,
# 'user-library-read',
# client_id='97537d196d1345ecb17c19537d54174a',
# client_secret='003cf70c6be14a9e991e75f52930c5e3',
# redirect_uri='http://localhost:8080')
# sp = spotipy.Spotify(auth=token)
# tracks = sp.tracks(minPlaylist[:25])
# for value in tracks['tracks']:
# print(value['name'])
# for artist in value['artists']:
# print(" " + artist['name'])
int The duration of the track in milliseconds.
float A confidence measure from 0.0 to 1.0 of whether the track is acoustic. 1.0 represents high confidence the track is acoustic. The distribution of values for this feature look like this:Acousticness distribution
float Danceability describes how suitable a track is for dancing based on a combination of musical elements including tempo, rhythm stability, beat strength, and overall regularity. A value of 0.0 is least danceable and 1.0 is most danceable. The distribution of values for this feature look like this:Danceability distribution
float Energy is a measure from 0.0 to 1.0 and represents a perceptual measure of intensity and activity. Typically, energetic tracks feel fast, loud, and noisy. For example, death metal has high energy, while a Bach prelude scores low on the scale. Perceptual features contributing to this attribute include dynamic range, perceived loudness, timbre, onset rate, and general entropy. The distribution of values for this feature look like this:Energy distribution
float Predicts whether a track contains no vocals. “Ooh” and “aah” sounds are treated as instrumental in this context. Rap or spoken word tracks are clearly “vocal”. The closer the instrumentalness value is to 1.0, the greater likelihood the track contains no vocal content. Values above 0.5 are intended to represent instrumental tracks, but confidence is higher as the value approaches 1.0. The distribution of values for this feature look like this:Instrumentalness distribution
float Detects the presence of an audience in the recording. Higher liveness values represent an increased probability that the track was performed live. A value above 0.8 provides strong likelihood that the track is live. The distribution of values for this feature look like this:Liveness distribution
float The overall loudness of a track in decibels (dB). Loudness values are averaged across the entire track and are useful for comparing relative loudness of tracks. Loudness is the quality of a sound that is the primary psychological correlate of physical strength (amplitude). Values typical range between -60 and 0 db. The distribution of values for this feature look like this:Loudness distribution
float Speechiness detects the presence of spoken words in a track. The more exclusively speech-like the recording (e.g. talk show, audio book, poetry), the closer to 1.0 the attribute value. Values above 0.66 describe tracks that are probably made entirely of spoken words. Values between 0.33 and 0.66 describe tracks that may contain both music and speech, either in sections or layered, including such cases as rap music. Values below 0.33 most likely represent music and other non-speech-like tracks. The distribution of values for this feature look like this:Speechiness distribution
float A measure from 0.0 to 1.0 describing the musical positiveness conveyed by a track. Tracks with high valence sound more positive (e.g. happy, cheerful, euphoric), while tracks with low valence sound more negative (e.g. sad, depressed, angry). The distribution of values for this feature look like this:Valence distribution
float The overall estimated tempo of a track in beats per minute (BPM). In musical terminology, tempo is the speed or pace of a given piece and derives directly from the average beat duration. The distribution of values for this feature look like this:Tempo distribution